/*
 * @Date: 2023-01-22 02:17:37
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 04:11:59
 * @FilePath: \campus-repair-platform\server\routes\reception\userinfo.js
 */
const express = require("express")
// 创建路由对象
const router = express.Router()

// 导入用户路由处理函数模块
const userinfoService = require("../../service/reception/userinfo")
// 导入验证表单数据的中间件
const expressJoi = require('@escook/express-joi')
// 导入需要的验证规则对象
const {
  update_phone_schema,
  info_phone_schema,
  update_pwd_oldPwd_schema,
  verify_code_schema
} = require("../../schema/reception/user")


// 退出登录
router.get('/logout', userinfoService.logout)
// 获取个人信息
router.get("/", userinfoService.getUserinfo)
// 获取个人类型
router.get("/type", userinfoService.getUserinfoType)

// 获取已存在手机获取验证码
router.get("/old_code", userinfoService.getCode)

// 获取不存在手机获取验证码
router.post("/new_code", expressJoi(info_phone_schema), userinfoService.newCode)

// 验证验证码
router.post("/valid_code", expressJoi(verify_code_schema), userinfoService.validCode)

// 修改手机号
router.patch(
  "/phone",
  expressJoi(update_phone_schema),
  userinfoService.updatePhone
)
// 修改密码
router.patch(
  "/password",
  expressJoi(update_pwd_oldPwd_schema),
  userinfoService.updatePwdOldPwd
)

module.exports = router
